function close_win() {
	document.getElementById("comm_window").style.display = "none";
}

function CountLimit(){
	with(document.LIDFrm){
		if(EventLimit.value.length == 0)EventLimit.value = "0";
		if(isNaN(EventLimit.value))EventLimit.value = "0";
		if(parseInt(MaxEventLimit.value) >= 0 && parseInt(MaxEventLimit.value) < parseInt(EventLimit.value))EventLimit.value = MaxEventLimit.value;
		BetLimit.value = eval(EventLimit.value)/2;
		if(parseInt(MaxBetLimit.value) >= 0 && parseInt(MaxBetLimit.value) < parseInt(BetLimit.value))BetLimit.value = MaxBetLimit.value;
		if(ECRate != null){
			document.getElementById("EventLimitER").innerHTML=Math.round(parseFloat(EventLimit.value)/ECRate);
			document.getElementById("BetLimitER").innerHTML=Math.round(parseFloat(BetLimit.value)/ECRate);
		}
	}
}


function CountBLimit(){
	with(document.beMemberFrm){
		if(parseInt(EventLimit.value) < parseInt(BetLimit.value))BetLimit.value = EventLimit.value;
		if(parseInt(MaxBetLimit.value) >= 0 && parseInt(MaxBetLimit.value) < parseInt(BetLimit.value))BetLimit.value = MaxBetLimit.value;
		if(ECRate != null){
			document.getElementById("BetLimitER").innerHTML=Math.round(parseFloat(BetLimit.value)/ECRate);
		}
	}
}


function CommValueChange(intLID, intBT, intGT, intGap, intMinComm){
	var objComm = document.getElementById("arrComm"+intLID+"_"+intBT+"_"+intGT);
	var intNewComm = objComm.value*1 + intGap*1;
	if(intNewComm < intMinComm*1)intNewComm = intMinComm*1;
	if(intNewComm > 100)intNewComm = 100;
	objComm.value = Math.round(intNewComm*100)/100;
}

function ShowEditLayer(strTip, strLID, strBT, strEvent, strBet, strMaxEvent, strMaxBet, strGap, strComm1, strMinComm1, strComm2, strMinComm2, strComm3, strMinComm3, strAcceptLimit) {
	var i = 0, j = 0, flMinComm = 0, flComm = 0, intGT = 0, intTop = 0, intLeft = 0;
	var flGap = parseFloat(strGap);
	document.getElementById("comm_title").innerHTML = strTip;
	for(intGT = 1; intGT <= 3; intGT++){
		while (document.LIDFrm["Comm"+intGT].length){
			document.LIDFrm["Comm"+intGT].options[0] = null;
		}

		flMinComm = eval("strMinComm"+intGT);
		flComm = eval("strComm"+intGT);
		j = 0;
		for(i = 100; i >= flMinComm; i -= flGap){
			i = Math.round(i*100) / 100;
			document.LIDFrm["Comm"+intGT].options[j] = new Option(i,i);
			if(Math.round(i*100) == Math.round(flComm*100)) document.LIDFrm["Comm"+intGT].selectedIndex = j;
			j++;
		}
	} //for(intGT = 1; intGT <= 3; intGT++){

	//document.LIDFrm.BallType.value=strBall;
	document.LIDFrm.BetType.value=strBT;
	document.LIDFrm.EventLimit.value=strEvent;
	document.LIDFrm.BetLimit.value=strBet;
	document.LIDFrm.MaxEventLimit.value=strMaxEvent;
	document.LIDFrm.MaxBetLimit.value=strMaxBet;
	if(document.LIDFrm.AcceptLimit != null){
		document.LIDFrm.AcceptLimit.value=strAcceptLimit;
		document.LIDFrm.AcceptLimit.disabled = (strLID == 4 && strBT >= 7 && strBT <= 11)?false:true;
	}
	if(event)intTop = (document.body.scrollTop + event.clientY + 15) + "";
	intLeft = (document.body.scrollLeft + event.clientX - 20) + "";
	if(intTop.length > 0)comm_window.style.top = intTop;
	if(intLeft.length > 0)comm_window.style.left = intLeft; 
	document.getElementById("comm_window").style.display = "block";
}

function ShowMemberEditLayer(strTip, strBall, strBT, strEvent, strBet, strMaxEvent, strMaxBet, strGap, strComm, strMinComm) {
	var i = 0, j = 0, flMinComm = 0, flComm = 0, intTop = 0, intLeft = 0;
	var flGap = parseFloat(strGap);
	document.getElementById("comm_title").innerHTML = strTip;
	while (document.LIDFrm["Comm"].length){
		document.LIDFrm["Comm"].options[0] = null;
	}

	flMinComm = eval("strMinComm");
	flComm = eval("strComm");
	j = 0;
	for(i = 100; i >= flMinComm; i -= flGap){
		i = Math.round(i*100) / 100;
		document.LIDFrm["Comm"].options[j] = new Option(i,i);
		if(Math.round(i*100) == Math.round(flComm*100)) document.LIDFrm["Comm"].selectedIndex = j;
		j++;
	}

	//document.LIDFrm.BallType.value=strBall;
	document.LIDFrm.BetType.value=strBT;
	document.LIDFrm.EventLimit.value=strEvent;
	document.LIDFrm.BetLimit.value=strBet;
	document.LIDFrm.MaxEventLimit.value=strMaxEvent;
	document.LIDFrm.MaxBetLimit.value=strMaxBet;
	document.getElementById("EventLimitER").innerHTML=Math.round(parseFloat(strEvent)/ECRate);
	document.getElementById("BetLimitER").innerHTML=Math.round(parseFloat(strBet)/ECRate);

	if(event)intTop = (document.body.scrollTop + event.clientY + 15) + "";
	intLeft = (document.body.scrollLeft + event.clientX - 20) + "";
	if(intTop.length > 0)comm_window.style.top = intTop;
	if(intLeft.length > 0)comm_window.style.left = intLeft; 
	document.getElementById("comm_window").style.display = "block";
}

//退水下拉圖層
var inputField;
var completeDiv;
var glineTable;
var glineTableBody;

function initVars(strGLineName) {
	inputField = document.getElementById(strGLineName);            
	glineTable = document.getElementById("gline_table");
	completeDiv = document.getElementById("popup_gline");
	glineTableBody = document.getElementById("gline_table_body");
}

function setGLineLayer(strGLineName, glGap, flMinV) { 
	initVars(strGLineName);
	clearGLine();
	setOffsets();

	var row, cell, txtNode, i;
	for (i = 100; i >= flMinV; i-=glGap) {
		var nextNode = Math.round(i*100)/100;//the_names[i].firstChild.data;
		row = document.createElement("tr");
		cell = document.createElement("td");
        
		cell.className='mouseOver';
		cell.onmouseout = function() {this.className='mouseOver';};
		cell.onmouseover = function() {this.className='mouseOut';};
		cell.setAttribute("bgcolor", "#FFFAFA");
		cell.setAttribute("border", "0");
		cell.onclick = function() { populateGLine(this); };

		txtNode = document.createTextNode(nextNode);
		cell.appendChild(txtNode);
		row.appendChild(cell);
		glineTableBody.insertBefore(row);
	}
}

function setOffsets() {
	var end = inputField.offsetWidth + 20;
	var left = calculateOffsetLeft(inputField);
	var top = calculateOffsetTop(inputField) + inputField.offsetHeight;

	completeDiv.style.display = "block";
	completeDiv.style.left = left + "px";
	completeDiv.style.top = top + "px";
	completeDiv.style.width = end + "px";
	glineTable.style.width = end + "px";
}

function calculateOffsetLeft(field) {
	return calculateOffset(field, "offsetLeft");
}

function calculateOffsetTop(field) {
	return calculateOffset(field, "offsetTop");
}

function calculateOffset(field, attr) {
	var offset = 0;
	while(field) {
		offset += field[attr]; 
		field = field.offsetParent;
	}
	return offset;
}

function populateGLine(cell) {
	inputField.value = cell.firstChild.nodeValue;
	clearGLine();
}

function clearGLine() {
	var ind = glineTableBody.childNodes.length;
	for (var i = ind - 1; i >= 0 ; i--) {
		glineTableBody.removeChild(glineTableBody.childNodes[i]);
	}
	completeDiv.style.display = "none";
}